package javafx.com;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.input.KeyCharacterCombination;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyCombination;
import javafx.scene.input.Mnemonic;
import javafx.stage.Stage;

public class main extends Application {
	
	public static void main(String[] args) {
		launch(args);
	}

	@Override
	public void start(Stage primaryStage) throws Exception {
		Button button = new Button();
		button.setText("字体");

		button.setLayoutX(100);
		button.setLayoutY(100);
		button.setPrefWidth(200);
		button.setPrefHeight(200);
		
		button.setOnAction((ActionEvent)->{
			System.out.println("setOnAction");
		});
		
		Group group = new Group();
		group.getChildren().add(button);

		Scene scene = new Scene(group);

		// 设置键盘快捷键
		KeyCombination kc1 = new KeyCodeCombination(KeyCode.C,KeyCombination.ALT_DOWN,KeyCombination.CONTROL_DOWN);
		Mnemonic mnemonic = new Mnemonic(button, kc1);
		scene.addMnemonic(mnemonic);
		
		// 方式二
		KeyCombination kc2 = new KeyCharacterCombination("X",KeyCombination.ALT_DOWN,KeyCombination.CONTROL_DOWN);
		Mnemonic mnemonic2 = new Mnemonic(button, kc2);
		scene.addMnemonic(mnemonic2);
		
		// 方法三
//		KeyCombination kc3 = new KeyCharacterCombination("X",KeyCombination.ALT_DOWN,KeyCombination.CONTROL_DOWN);
//		Mnemonic mnemonic3 = new Mnemonic(button, kc3);
//		scene.addMnemonic(mnemonic3);
		
		// 方法四
		KeyCombination kc4 = new KeyCodeCombination(KeyCode.C,KeyCombination.SHIFT_DOWN);
		scene.getAccelerators().put(kc4, ()->{
			System.out.println("run()方法");
			play();
		});
		
		primaryStage.setScene(scene);

		primaryStage.setTitle("javafx");
		primaryStage.setWidth(600);
		primaryStage.setHeight(600);
		primaryStage.show();

	}
	
	public void play() {
		System.out.println("play()方法");
	}

}
